<?php
/**
 * Customer Model
 *
 * @property Customer
 */
class Customer extends AppModel {
/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'name';

	# Validation rules.

    /**
     * associations
     *
     * @var array
    **/
	public $hasMany = array(
		'Sale' => array(
			'className' => 'Sale',
			'foreignKey' => 'customer_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
        'Proforma' => array(
            'className' => 'Proforma',
            'foreignKey' => 'customer_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
	);

    var $belongsTo = array(
        'Country' => array(
            'className' => 'Country',
            'foreignKey' => 'country_id',
            'conditions' => '',
            'order' => '',
            'limit' => '',
            'dependent' => false
        ),
        'Region' => array(
            'className' => 'Region',
            'foreignKey' => 'region_id',
            'conditions' => '',
            'order' => '',
            'limit' => '',
            'dependent' => false
        )
    );

    
    
    function getCustomerById($userId = null){
        $conditions = array(
           'Customer.id' => $userId,
           'Customer.deleted' => 'n'
        );
        # fetch the specific data from the server and retrun it.
        return  $this->find('first', array('conditions' => $conditions, 'recursive' => -1));
    }
    
   
}
